package com.mmall.Concurrency.example.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

@Slf4j
public class FutureTaskExample {


    public static void main(String[] args) throws Exception {
        FutureTask<String> futureTask = new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {     //直接对Callable的返回值进行设置
                log.info("do sth in callable");
                Thread.sleep(5000);
                return "Done";
            }
        });

        new Thread(futureTask).start();
        log.info("do sth in main");
        Thread.sleep(5000);
         String res =futureTask.get();
         log.info("res : {}" ,res);    //可直接利用自己把自己的返回值取出来
    }
}
